//package com.sq.system.controller;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.CrossOrigin;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.BufferedReader;
//import java.io.File;
//import java.io.InputStreamReader;
//import java.nio.file.Files;
//import java.nio.file.Path;
//
//
//@RestController
//@CrossOrigin
//public class AutoDeploymentController {
//
//    private static final Logger log = LoggerFactory.getLogger(AutoDeploymentController.class);
//
//    @Value("${deploy.server.path}")
//    private String serverPath;
//
//    @PostMapping("/api/deploy")
//    public ResponseEntity<String> uploadFile(
//            @RequestParam("file") MultipartFile file,
//            @RequestParam("script") MultipartFile script) {
//
//        try {
//            // 验证文件类型
//            if (!file.getOriginalFilename().endsWith(".zip")) {
//                throw new IllegalArgumentException("仅支持ZIP格式");
//            }
//
//            // 存储到临时目录
//            Path tempDir = Files.createTempDirectory("deploy_");
//            file.transferTo(new File(tempDir + "/frontend.zip"));
//            script.transferTo(new File(tempDir + "/deploy.sh"));
//
//            // 调用部署脚本
//            String[] cmd = {"/bin/bash", "deploy.sh", tempDir.toString()};
//            Process process = Runtime.getRuntime().exec(cmd);
//
//            // 记录日志
//            BufferedReader reader = new BufferedReader(
//                    new InputStreamReader(process.getInputStream()));
//            String line;
//            while ((line = reader.readLine()) != null) {
//                log.info(line);
//            }
//            return ResponseEntity.ok("部署成功");
//        } catch (Exception e) {
//            log.error("部署失败", e);
//            return ResponseEntity.status(500).body(e.getMessage());
//        }
//    }
//}
//
